﻿using System.ComponentModel;
using System.Reflection;

namespace OpusSuite.Extensions
{
    public static class EnumExt
    {
        public static string GetDescription(System.Enum value)
        {
// ReSharper disable SpecifyACultureInStringConversionExplicitly
            FieldInfo fi = value.GetType().GetField(value.ToString());
// ReSharper restore SpecifyACultureInStringConversionExplicitly
            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (attributes.Length > 0)
                return attributes[0].Description;
            else
// ReSharper disable SpecifyACultureInStringConversionExplicitly
                return value.ToString();
// ReSharper restore SpecifyACultureInStringConversionExplicitly
        }
    }
}